from pod.std import *
import operator
import math

class ForLoop(Macro):
    name = "for"
    
    def __init__(self, ctx, **kwargs):
        self.var = kwargs.keys()[0]
        self.value = kwargs[self.var]
        self.ctx = ctx
    
    def __call__(self, content):
        result = []
        for i in self.value:
            #self.ctx.env["var:%s" % self.var] = i
            self.ctx.setVar(self.var, i)
            value = content.execute(self.ctx)
            result.extend(value)
        return result

class IfStatement(Macro):
    name = "if"
    
    def __init__(self, ctx, condition, true=None, false=None):
        super(IfStatement, self).__init__()
        self.condition = condition
        self.true = true
        self.false = false
        self.ctx = ctx
    
    def __call__(self, content):
        if self.condition: 
            return self.true.execute(self.ctx)
        else:
            return self.false.execute(self.ctx)
